var o, e = require, t = module, n = exports, i = this && this.__extends || (o = function(t, e) {
    return (o = Object.setPrototypeOf || {
        __proto__: []
    } instanceof Array && function(t, e) {
        t.__proto__ = e;
    } || function(t, e) {
        for (var o in e) e.hasOwnProperty(o) && (t[o] = e[o]);
    })(t, e);
}, function(t, e) {
    function n() {
        this.constructor = t;
    }
    o(t, e), t.prototype = null === e ? Object.create(e) : (n.prototype = e.prototype, 
    new n());
}), a = this && this.__decorate || function(t, e, o, n) {
    var i, a = arguments.length, r = a < 3 ? e : null === n ? n = Object.getOwnPropertyDescriptor(e, o) : n;
    if ("object" == typeof Reflect && "function" == typeof Reflect.decorate) r = Reflect.decorate(t, e, o, n); else for (var s = t.length - 1; 0 <= s; s--) (i = t[s]) && (r = (a < 3 ? i(r) : 3 < a ? i(e, o, r) : i(e, o)) || r);
    return 3 < a && r && Object.defineProperty(e, o, r), r;
};

Object.defineProperty(n, "__esModule", {
    value: !0
});

var r = e("GameData"), s = e("AudioManager"), c = e("DataManager"), l = e("LoadManager"), d = e("UIManager"), u = e("WebManager"), p = e("Global"), h = e("TimeView"), f = cc._decorator, g = f.ccclass, m = f.property, y = function(e) {
    function t() {
        var t = null !== e && e.apply(this, arguments) || this;
        return t.sprite = null, t.data = null, t.box = null, t.isEffect = !1, t.isDestory = !1, 
        t.timeView = null, t;
    }
    return i(t, e), t.prototype.onClick = function() {
        var e = this;
        s.default.getInstance().playAudio("按钮2"), this.isEffect || this.isDestory || (this.data.isVideo ? (d.default.getInstance().loadPopPnl("egg_reward", {
            type: p.RewardType.ARM,
            idx: this.data.idx
        }), this.doGet()) : !GA.isPlatform([ GA.Platform.ByteDance, GA.Platform.Kwaigame ]) || r.GD.isFollow ? this.doReward() : d.default.getInstance().loadPnl("eggsTips").then(function(t) {
            t && (t.target = e.node);
        }));
    }, t.prototype.onEnable = function() {
        var t;
        this.data && ((t = this.data.time) > Date.now() ? this.doTimer(t - Date.now()) : this.clear());
    }, t.prototype.start = function() {}, t.prototype.init = function(t) {
        var e = this;
        t.data && (this.data = t.data, l.default.getInstance().loadSpriteFrame({
            url: this.getUrl(this.data.idx),
            sprite: this.sprite
        })), t.box && (this.box = t.box, (this.box.newYearItem = this).node.setPosition(cc.v2(0, 800)), 
        this.isEffect = !0, cc.tween(this.node).by(.5, {
            position: cc.v3(0, -800)
        }).by(.1, {
            position: cc.v3(0, 20)
        }).by(.1, {
            position: cc.v3(0, -20)
        }).call(function() {
            e.isEffect = !1;
        }).start(), this.node.parent = this.box.node);
    }, t.prototype.clear = function() {
        var t = d.default.getInstance().getPnl("start");
        t ? (r.GD.gunIdx = r.GD.topRank, t.personView.changeGun(r.GD.topRank), this.box && (this.box.newYearItem = null), 
        this.node.destroy(), t.updateMatrix()) : (this.box && (this.box.newYearItem = null), 
        this.node.destroy());
    }, t.prototype.doReward = function() {
        u.default.getInstance().sentLog("获得皮肤武器id:" + this.data.idx), this.node.on("egg_get", this.doGet, this), 
        d.default.getInstance().loadPopPnl("egg_get", {
            type: p.RewardType.ARM,
            idx: this.data.idx,
            target: this.node
        });
    }, t.prototype.doGet = function() {
        this.data.isVideo = 1, r.GD.gunIdx = this.data.idx, c.default.getInstance().save(), 
        this.node.off("egg_get"), d.default.getInstance().hideAllPnl(), d.default.getInstance().showPnl("start");
    }, t.prototype.getUrl = function(t) {
        return 3e3 <= t ? "texture/armOlympic/" + t : 2e3 <= t ? "image/arm_draw/" + (t - 2e3) : 1e3 <= t ? "image/arm3/" + (t - 1e3) : "image/arm/" + t;
    }, t.prototype.getTimer = function() {
        var n = this;
        return new Promise(function(e, o) {
            n.timeView ? e(n.timeView) : l.default.getInstance().loadRes({
                url: "prefab/time",
                type: cc.Prefab
            }).then(function(t) {
                n.timeView = cc.instantiate(t).getComponent(h.default), n.timeView ? (n.timeView.node.parent = n.node, 
                n.timeView.node.setPosition(cc.v2(0, 60)), e(n.timeView)) : o();
            }).catch(function() {
                o();
            });
        });
    }, t.prototype.doTimer = function(e) {
        var o = this;
        this.getTimer().then(function(t) {
            t.init(Math.floor(e / 1e3)), t.startTimer(), t.node.on("finished", o.clear, o);
        });
    }, a([ m(cc.Sprite) ], t.prototype, "sprite", void 0), a([ g ], t);
}(cc.Component);

n.default = y;